<?php
/**
 * @name Registry
 *
 * LICENSE
 *
 * This source file is subject to the BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.phpxe.com/license/
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to Chaodong.Sheng <scd113@gmail.com> so we can send you a copy immediately.
 *
 * @category   Registry of Scd Framework
 * @package    Scd
 * @copyright  Copyright (c) 2007 PHPXe Web Studio <http://www.phpxe.com>
 * @license    http://framework.phpxe.com/license/
 * @version    $Id: Registry.php Thu Sep 20 00:09:09 CST 2007 Davy $
 */
include_once("Scd/Exception.php");
class Scd_Registry extends ArrayObject {
	/**
     * getter method, basically same as offsetGet().
     *
     * This method can be called from an object of type Scd_Registry, or it
     * can be called statically.  In the latter case, it uses the default
     * static instance stored in the class.
     *
     * @param string $index - get the value associated with $index
     * @return mixed
     * @throws Scd_Exception if no entry is registerd for $index.
     */
	function get($index)
	{
		$instance = new Scd_Registry();

		if (!$instance->offsetExists($index)) {
			require_once 'Scd/Exception.php';
			return new Scd_Exception("No entry is registered for key '$index'");
		}

		return $instance->offsetGet($index);
	}

	/**
     * setter method, basically same as offsetSet().
     *
     * This method can be called from an object of type Scd_Registry, or it
     * can be called statically.  In the latter case, it uses the default
     * static instance stored in the class.
     *
     * @param string $index The location in the ArrayObject in which to store
     *   the value.
     * @param mixed $value The object to store in the ArrayObject.
     * @return void
     */
	function set($index, $value)
	{
		//$instance = $this->getInstance();
		$instance = new Scd_Registry();
		$instance->offsetSet($index, $value);
		return $instance->offsetGet($index);
	}
	
	function toString()
	{
		return get_class($this);
	}
}